package com.pkk.penguin.frame.know.shiro.shirodemo.springversion.dbsource;

import com.pkk.penguin.frame.know.shiro.shirodemo.springversion.entity.TbUserEntity;
import com.pkk.penguin.frame.know.shiro.shirodemo.springversion.entity.resource.ResourceRole;
import com.pkk.penguin.frame.know.shiro.shirodemo.springversion.entity.role.RoleEntity;
import com.pkk.penguin.frame.know.shiro.shirodemo.springversion.mapper.TbUserMapper;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * @description: 用户DB业务层
 * @author: peikunkun
 * @create: 2018-08-22 10:22
 **/
@Service
public class TbUserDbService {

  @Resource
  private TbUserMapper tbUserMapper;

  /**
   * @Description: 根据账户获取用户信息
   * @Param: a
   * @return: a
   * @Author: peikunkun
   * @Date: 2018/8/22 0022 下午 5:33
   */
  public TbUserEntity selectUserInfoByName(String uName) {
    return tbUserMapper.selectUserInfoByName(uName);
  }

  /**
   * @Description: 根据账户id获取用户信息
   * @Param: a
   * @return: a
   * @Author: peikunkun
   * @Date: 2018/8/22 0022 下午 5:33
   */
  public TbUserEntity selectUserInfoById(Long id) {
    return tbUserMapper.selectUserInfoById(id);
  }

  /**
   * @Description: 更新最后登录时间
   * @Param: [id]
   * @return: void
   * @Author: peikunkun
   * @Date: 2018/8/23 0023 下午 12:46
   */
  public Integer updateUserLastLoginTimeById(Long id) {
    return tbUserMapper.updateUserLastLoginTimeById(id);
  }

  /**
   * @Description: 查询当前用户的角色
   * @Param: [userId]
   * @return: java.util.List<com.pkk.com.pkk.penguin.frame.know.shiro.shirodemo.springversion.entity.user.RoleEntity>
   * @Author: peikunkun
   * @Date: 2018/8/29 0029 下午 1:16
   */
  public List<RoleEntity> selectUserRoleByUserId(Long userId) {
    return tbUserMapper.selectUserRoleByUserId(userId);
  }

  /**
   * @Description: 查询当前用户的角色
   * @Param: [userId]
   * @return: java.util.List<com.pkk.com.pkk.penguin.frame.know.shiro.shirodemo.springversion.entity.user.RoleEntity>
   * @Author: peikunkun
   * @Date: 2018/8/29 0029 下午 1:16
   */
  public List<RoleEntity> selectUserRoleByUserName(String userName) {
    return tbUserMapper.selectUserRoleByUserName(userName);
  }

  public List<ResourceRole> getAllResource() {
    return tbUserMapper.getAllResource();
  }

  public List<ResourceRole> getAllResourceByRoles(Long[] roles) {
    return tbUserMapper.getAllResourceByRoles(roles);
  }
}
